<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>找出最小值</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.min" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">min</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">min</span> &mdash; <span class="dc-title">找出最小值</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.min-description">
  <h3 class="title">说明</h3>
   <div class="methodsynopsis dc-description">
    <span class="methodname"><strong>min</strong></span>
     ( <span class="methodparam"><span class="type">array</span> <code class="parameter">$values</code></span>
    ) : <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span></div>

   <div class="methodsynopsis dc-description">
    <span class="methodname"><strong>min</strong></span>
     ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value1</code></span>
    , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value2</code></span>
    [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$...</code></span>
   ] ) : <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span></div>

  <p class="para rdfs-comment">
   如果仅有一个参数且为数组，<span class="function"><strong>min()</strong></span>
   返回该数组中最小的值。如果给出了两个或更多参数,
   <span class="function"><strong>min()</strong></span> 会返回这些值中最小的一个。
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    PHP 会将非数值的 <span class="type"><a href="language.types.string.html" class="type string">string</a></span> 当成
    <em>0</em>，但如果这个正是最小的数值则仍然会返回一个字符串。如果多个参数都求值为
    <em>0</em> 且是最小值，<span class="function"><strong>min()</strong></span>
    会返回按字母表顺序最小的字符串，如果其中没有字符串的话，则返回数值的 <em>0</em>。
   </p>
  </p></blockquote>
 </div>

  <div class="refsect1 parameters" id="refsect1-function.min-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">values</code></dt>

     <dd>

      <p class="para">
       包含值的数组。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">value1</code></dt>

     <dd>

      <p class="para">
       Any <a href="language.operators.comparison.html" class="link">comparable</a>
       value.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">value2</code></dt>

     <dd>

      <p class="para">
       Any <a href="language.operators.comparison.html" class="link">comparable</a>
       value.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">...</code></dt>

     <dd>

      <p class="para">
       Any <a href="language.operators.comparison.html" class="link">comparable</a>
       value.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.min-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   <span class="function"><strong>min()</strong></span> 返回参数中数值最小的。
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.min-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4133">
    <p><strong>Example #1 <span class="function"><strong>min()</strong></span> 用法的例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">min</span><span style="color: #007700">(</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">6</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">7</span><span style="color: #007700">);&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;1<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">min</span><span style="color: #007700">(array(</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">4</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">));&nbsp;</span><span style="color: #FF8000">//&nbsp;2<br /><br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">min</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'hello'</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;0<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">min</span><span style="color: #007700">(</span><span style="color: #DD0000">'hello'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;hello<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">min</span><span style="color: #007700">(</span><span style="color: #DD0000">'hello'</span><span style="color: #007700">,&nbsp;-</span><span style="color: #0000BB">1</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;-1<br /><br />//&nbsp;对多个数组，min&nbsp;从左向右比较。<br />//&nbsp;因此在本例中：2&nbsp;==&nbsp;2，但&nbsp;4&nbsp;&lt;&nbsp;5<br /></span><span style="color: #0000BB">$val&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">min</span><span style="color: #007700">(array(</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">4</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">8</span><span style="color: #007700">),&nbsp;array(</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">));&nbsp;</span><span style="color: #FF8000">//&nbsp;array(2,&nbsp;4,&nbsp;8)<br /><br />//&nbsp;如果同时给出数组和非数组作为参数，则不可能返回数组，因为<br />//&nbsp;数组被视为最大的<br /></span><span style="color: #0000BB">$val&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">min</span><span style="color: #007700">(</span><span style="color: #DD0000">'string'</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">7</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">42</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;string<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.min-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="max.html" class="function" rel="rdfs-seeAlso">max()</a> - 找出最大值</span></li>
    <li class="member"><span class="function"><a href="count.html" class="function" rel="rdfs-seeAlso">count()</a> - 计算数组中的单元数目，或对象中的属性个数</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>